package com.xiegang.serviceMap.remote;

import com.xiegang.internalcommon.constant.AmapConfigConstants;
import com.xiegang.internalcommon.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @author xieGang
 * @description
 * @date 2023/3/18 13:37
 **/
@Service
public class MapDicDistrictClent {

    @Value("${Amap.key}")
    private String key;

    @Autowired
    private RestTemplate restTemplate;

    public String dicDistrict(String keywords){

        //https://restapi.amap.com/v3/config/district?keywords=北京&subdistrict=2&key=<用户的key>
        StringBuilder url = new StringBuilder();
        url.append(AmapConfigConstants.DISRICT_URL);
        url.append("?");
        url.append("keywords="+keywords);
        url.append("&");
        url.append("subdistrict=3");
        url.append("&");
        url.append("key="+key);

        ResponseEntity<String> forEntity = restTemplate.getForEntity(url.toString(), String.class);

        return forEntity.getBody();
    }
}
